﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



namespace MyNet.WebUI {

    using MyNet.WebUI.MyNetDbService;

    public partial class Contacts : System.Web.UI.Page {

        protected void Page_Load( object sender, EventArgs e ) {

            //Label1.Text = (String) Session["FacebookAccessToken"];
        } // Method

        protected void AddContactButton_Click( object sender, EventArgs e ) {

            // Service client
            var myNetDbService = new MyNetDbServiceClient();

            // Create Contact object based on info in Text fields
            var contact = new Contact {
                Firstname = FirstnameTextBox.Text,
                Lastname = LastnameTextBox.Text
            };

            // Send the New Contact to the service for insertion in DB
            myNetDbService.addContact ( contact );

            // Update the interface
            ContactsGridView.DataBind ();
            FirstnameTextBox.Text = "";
            LastnameTextBox.Text = "";

        }

        protected void ImportFacebookContactsButton_Click( object sender, EventArgs e ) {

            // Service client
            var myNetDbService = new MyNetDbServiceClient();

            var facebookUsername = (String) Session["FacebookUsername"];
            var facebookAccessToken = (String) Session["FacebookAccessToken"];

            myNetDbService.addFacebookUserFriends( facebookUsername, facebookAccessToken );

            // Update the interface
            ContactsGridView.DataBind();

        }

        protected void RemoveContactsButton_Click( object sender, EventArgs e ) {

            new MyNetDbServiceClient().removeContacts();
            
            // Update the interface
            ContactsGridView.DataBind();


        }

        protected void Button1_Click( object sender, EventArgs e ) {
            System.Threading.Thread.Sleep( 5000 );
        } // Method

    } // Class
}